﻿using System;
using System.Collections.ObjectModel;
using VisualWip.Core.Columns;
using VisualWip.Core.Interfaces;

namespace VisualWip.Core
{
    public class Window :IPersistable
    {
        public const string MainWindowName = "MainWindow";

        public Window()
        {
            WindowColumns = new ObservableCollection<Column>();
        }

        public bool IsMainWindow
        {
            get { return WindowName == MainWindowName; }
        }

        public string WindowName { get; set; }

        public ObservableCollection<Column> WindowColumns { get; private set; }

        public int WindowNumber { get; set; }

        public void Refresh(bool refreshAsync)
        {
            foreach (Column column in WindowColumns)
            {
                column.Refresh(refreshAsync);
            }
        }

        public PersistenceTree Persist(string name)
        {
            var settings = new PersistenceTree(name, this);
            settings.Add(()=> WindowName);
            settings.Add(() => WindowNumber);
            return settings;
        }

        public void Load(PersistenceTree settings)
        {
            WindowName = settings.Get(() => WindowName,string.Empty);
            WindowNumber = settings.Get(() => WindowNumber,0);
        }
    }
}